package marshallerTest;

import java.io.*;

import org.exolab.castor.xml.*;

import org.exolab.castor.mapping.*;

public class ZhuwTest2

{

	public static void main(String[] argv) {

//		String str = "asdfasdfasdf" +
//				"asdfff    ffffffj";
//		String s2 = str.replaceAll("\r\n", "m");
//		System.out.println(s2);
		
		// build a test bean

		FlightBean bean = new FlightBean();

		bean.setCarrier("AR");

		bean.setNumber(426);

		bean.setDepartureTime("6:23a");

		bean.setArrivalTime("8:42a");

		try {

			// write it out as XML

			Mapping map = new Mapping();

			map.loadMapping("d:\\mapping2.xml");

			File file = new File("d:\\test2.xml");

			Writer writer = new FileWriter(file);

			Marshaller marshaller = new Marshaller(writer);

			marshaller.setMapping(map);

			marshaller.marshal(bean);

			// now restore the value and list what we get

			Reader reader = new FileReader(file);

			Unmarshaller unmarshaller = new Unmarshaller(map);

			FlightBean read = (FlightBean) unmarshaller.unmarshal(reader);

			System.out.println("Flight " + read.getCarrier() +

			read.getNumber() + " departing at " +

			read.getDepartureTime() + " and arriving at "
					+ read.getArrivalTime());

		} catch (IOException ex) {

			ex.printStackTrace(System.err);

		} catch (MarshalException ex) {

			ex.printStackTrace(System.err);

		} catch (ValidationException ex) {

			ex.printStackTrace(System.err);

		}

		catch (MappingException ex) {

			ex.printStackTrace(System.err);

		}

	}

}
